//
//  TextView.m
//  TextApplication
//
//  Created by dllo on 16/8/29.
//  Copyright © 2016年 yh. All rights reserved.
//

#import "TextView.h"
#import "TAMacro.h"
#import "TitleCollectionViewCell.h"
#import "ClassifyTableViewCell.h"
#import "UIImageView+WebCache.h"

@interface TextView () <UICollectionViewDataSource, UICollectionViewDelegate>
@property (nonatomic, strong) NSArray *titleArray;
@property (nonatomic, strong) UIView *aView;

@property (nonatomic, strong) UIImageView *imageView1;
@property (nonatomic, strong) UIImageView *imageView2;
@property (nonatomic, strong) UIImageView *imageView3;
@property (nonatomic, strong) UIImageView *imageView4;
@property (nonatomic, strong) UIImageView *imageView5;
@property (nonatomic, strong) UIImageView *imageView6;
@property (nonatomic, strong) UIImageView *imageView7;

@property (nonatomic, copy) NSString *str6;
@property (nonatomic, copy) NSString *str5;
@property (nonatomic, copy) NSString *str4;
@property (nonatomic, copy) NSString *str3;
@property (nonatomic, copy) NSString *str2;
@property (nonatomic, copy) NSString *str1;
@property (nonatomic, copy) NSString *str0;

@end

@implementation TextView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.titleArray = [NSArray array];
    }
    return self;
}

+ (UIView *)createThisViewWithImage:(UIImage *)image {
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 42, 40)];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(35, 8, 2, 24)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    UIImageView *phoneImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 7, 20, 26)];
    phoneImageView.image = image;
    [leftView addSubview:phoneImageView];
    [leftView addSubview:lineView];

    return leftView;
}

+ (UIButton *)createButtonWithImage:(UIImage *)image {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 20, 20);
    [button setImage:image forState:UIControlStateNormal];
    return button;
}

- (void)createTitleViewWithFrame:(CGRect)viewFrame collectionViewFrame:(CGRect)collectionViewFrame{
    self.titleArray = [NSArray array];
    UIView *aView = [[UIView alloc] initWithFrame:viewFrame];
    aView.backgroundColor = [UIColor blackColor];
    [self addSubview:aView];
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(collectionViewFrame.size.width / 11, 20);
    layout.minimumInteritemSpacing = collectionViewFrame.size.width / 11;
    layout.minimumLineSpacing = 0;
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:collectionViewFrame collectionViewLayout:layout];
    collectionView.backgroundColor = [UIColor blackColor];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    [collectionView registerClass:[TitleCollectionViewCell class] forCellWithReuseIdentifier:@"reuse"];
    [aView addSubview:collectionView];
    self.titleArray = @[@"分类", @"品牌", @"首页", @"专题", @"礼物"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TitleCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.titleLabel.text = self.titleArray[indexPath.row];
    return cell;
}

- (UIView *)createViewFrame:(CGRect)frame {
    UIView *aView = [[UIView alloc] initWithFrame:frame];
    self.imageView1 = [[UIImageView alloc] init];
        self.imageView1.frame = CGRectMake(0, 240, aView.bounds.size.width / 2, aView.bounds.size.width / 2 + 50);
    self.imageView1.backgroundColor = [UIColor grayColor];
    self.imageView1.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap1Action:)];
    [self.imageView1 addGestureRecognizer:tap1];
    [aView addSubview:self.imageView1];
    
    self.imageView2 = [[UIImageView alloc] init];
    self.imageView2.frame = CGRectMake(aView.bounds.size.width / 2, 240, aView.bounds.size.width / 2, aView.bounds.size.width / 2);
    self.imageView2.backgroundColor = [UIColor grayColor];
    self.imageView2.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap2Action:)];
    [self.imageView2 addGestureRecognizer:tap2];
    [aView addSubview:self.imageView2];
    
    self.imageView3 = [[UIImageView alloc] init];
    self.imageView3.frame = CGRectMake(0, 240 + aView.bounds.size.width / 2 + 50, aView.bounds.size.width / 2, aView.bounds.size.width / 2);
    self.imageView3.backgroundColor = [UIColor grayColor];
    self.imageView3.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap3Action:)];
    [self.imageView3 addGestureRecognizer:tap3];
    [aView addSubview:self.imageView3];

    self.imageView4 = [[UIImageView alloc] init];
    self.imageView4.frame = CGRectMake(aView.bounds.size.width / 2,aView.bounds.size.width / 2 + 240, aView.bounds.size.width / 2, aView.bounds.size.width / 2 + 50);
    self.imageView4.backgroundColor = [UIColor grayColor];
    self.imageView4.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap4Action:)];
    [self.imageView4 addGestureRecognizer:tap4];
    [aView addSubview:self.imageView4];
    
    self.imageView5 = [[UIImageView alloc] init];
    self.imageView5.frame = CGRectMake(0, aView.bounds.size.width + 240 + 50, aView.bounds.size.width, 240);
    self.imageView5.backgroundColor = [UIColor grayColor];
    self.imageView5.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap5Action:)];
    [self.imageView5 addGestureRecognizer:tap5];
    [aView addSubview:self.imageView5];

    self.imageView6 = [[UIImageView alloc] init];
    self.imageView6.frame = CGRectMake(0, aView.bounds.size.width + 480, aView.bounds.size.width / 2, aView.bounds.size.width / 2);
    self.imageView6.backgroundColor = [UIColor grayColor];
    self.imageView6.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap6 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap6Action:)];
    [self.imageView6 addGestureRecognizer:tap6];

    [aView addSubview:self.imageView6];

    self.imageView7 = [[UIImageView alloc] init];
    self.imageView7.frame = CGRectMake(aView.bounds.size.width / 2, aView.bounds.size.width + 480, aView.bounds.size.width / 2, aView.bounds.size.width / 2);
    self.imageView7.backgroundColor = [UIColor grayColor];
             // 打开图片的用户交互
    self.imageView7.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap7 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap7Action:)];
    [self.imageView7 addGestureRecognizer:tap7];
    [aView addSubview:self.imageView7];
    return aView;
}

- (void)tap1Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str0];
}

- (void)tap2Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str1];
}
- (void)tap3Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str2];
}
- (void)tap4Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str3];
}
- (void)tap5Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str4];
}
- (void)tap6Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str5];
}
- (void)tap7Action:(UITapGestureRecognizer *)tap {
    [self.delegate sendUrl:self.str6];
}

- (void)setUrlArr:(NSMutableArray *)urlArr {
    _urlArr = urlArr;
    self.str6 = _urlArr[6];
    self.str5 = _urlArr[5];
    self.str4 = _urlArr[4];
    self.str3 = _urlArr[3];
    self.str2 = _urlArr[2];
    self.str1 = _urlArr[1];
    self.str0 = _urlArr[0];
}

- (void)setImageViewArray:(NSMutableArray *)imageViewArray {
    _imageViewArray = imageViewArray;
    [self.imageView1 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[0]]]];
    [self.imageView2 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[2]]]];
    [self.imageView3 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[1]]]];
    [self.imageView4 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[3]]]];
    [self.imageView5 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[4]]]];
    [self.imageView6 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[5]]]];
    [self.imageView7 sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@", self.imageViewArray[6]]]];

}
// setter方法中赋值
@end
